home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Strings / PString.h < prev    next >
Text File  |  1997-06-28  |  3KB  |  88 lines

  1. // PString.h
  2.  
  3. #ifndef PString_h
  4. #define PString_h
  5.  
  6. #ifndef Assert_h
  7. #include "Assert.h"
  8. #endif
  9. #ifndef Data_h
  10. #include "Data.h"
  11. #endif
  12. #ifndef ConstPString_h
  13. #include "ConstPString.h"
  14. #endif
  15.  
  16. class PString
  17.   {
  18.     private:
  19.         const Data space;
  20.  
  21.         Data TextSpace()                                                        { return space.Tail( 1 ); }
  22.         Data SpaceTail( uint32 where )                                    { return space.Tail( where + 1 ); }
  23.         Data UnusedSpace()                                                    { return space.Tail( Length() + 1 ); }
  24.         
  25.     public:
  26.         PString( Data );
  27.         PString( Data, PString );
  28.         PString( Data, ConstPString );
  29.         PString( Data, ConstStr255Param );
  30.         PString( Data, ConstData text );
  31.  
  32.         uint8 Length() const                                                    { return space[0]; }
  33.         URange32 Range() const                                                { return URange32( 0, Length() ); }
  34.         uint32 StorageLength() const                                        { return space.Length(); }
  35.         uint32 UnusedLength() const                                        { return space.Length() - space[0] - 1; }
  36.         
  37.         uint8& operator[]( uint32 i )                                        { Assert( i < Length() ); return space[i+1]; }
  38.         
  39.         const uint8& operator[]( uint32 i ) const                        { Assert( i < Length() ); return space[i+1]; }
  40.         
  41.         void Clear()                                                            { space[0] = 0; }
  42.         void Truncate( uint32 end );
  43.         void SetLength( uint32 );
  44.         
  45.         Data Text()                                                                { return Data( &space[1], Length() ); }
  46.         ConstData Text() const                                                { return ConstData( &space[1], Length() ); }
  47.         
  48.         ConstData Head( uint32 size ) const                                { return Text().Head( size ); }
  49.         ConstData Tail( uint32 position ) const                        { return Text().Tail( position ); }
  50.         ConstData Middle( URange32 range ) const                        { return Text().Middle( range ); }
  51.  
  52.         Data Head( uint32 size )                                            { return Text().Head( size ); }
  53.         Data Tail( uint32 position )                                        { return Text().Tail( position ); }
  54.         Data Middle( URange32 range )                                        { return Text().Middle( range ); }
  55.         
  56.         void operator=( ConstData );
  57.         void operator=( ConstPString string )                            { operator=( string.Text() ); }
  58.         void operator=( const PString& string )                        { operator=( string.Text() ); }
  59.         void operator=( ConstStr255Param string )                        { operator=( ConstPString( string ) ); }
  60.  
  61.         void operator+=( uint8 c );
  62.         void operator+=( ConstData );
  63.         void operator+=( ConstPString string )                            { operator+=( string.Text() ); }
  64.         void operator+=( const PString& string )                        { operator+=( string.Text() ); }
  65.         void operator+=( ConstStr255Param string )                    { operator+=( ConstPString( string ) ); }
  66.         
  67.         operator ConstStr255Param() const                                { return space.Start(); }
  68.         operator ConstPString() const                                        { return ConstPString( space.Start() ); }
  69.         operator Data()                                                        { return Text(); }
  70.         operator ConstData() const                                            { return Text(); }
  71.         
  72.         void Remove( URange32 );
  73.         
  74.         void Insert( uint32 where, uint8 c );
  75.         void Insert( uint32 where, ConstData );
  76.         void Insert( uint32 where, ConstPString string )            { Insert( where, string.Text() ); }
  77.         void Insert( uint32 where, PString string )                    { Insert( where, string.Text() ); }
  78.         void Insert( uint32 where, ConstStr255Param string )        { Insert( where, ConstPString( string ) ); }
  79.         
  80.         void Replace( URange32 where, uint8 c );
  81.         void Replace( URange32 where, ConstData );
  82.         void Replace( URange32 where, ConstPString string )        { Replace( where, string.Text() ); }
  83.         void Replace( URange32 where, PString string )                { Replace( where, string.Text() ); }
  84.         void Replace( URange32 where, ConstStr255Param string )    { Replace( where, ConstPString( string ) ); }
  85.   };
  86.  
  87. #endif
  88.